Revision f3813541 ChatSecure/Classes/View Controllers/OTRMessagesViewController.m
| ChatSecure/Classes/View Controllers/OTRMessagesViewController.m | ||
|---|---|---|
| 69 | 69 |
OTRDropDownTypePush = 2 |
| 70 | 70 |
}; |
| 71 | 71 |
|
| 72 |
@interface OTRMessagesViewController () <UITextViewDelegate, OTRAttachmentPickerDelegate, OTRYapViewHandlerDelegateProtocol, OTRMessagesCollectionViewFlowLayoutSizeProtocol, OTRMessagesCollectionViewFlowLayoutSupplementaryViewProtocol, OTRRoomOccupantsViewControllerDelegate> {
|
|
| 72 |
@interface OTRMessagesViewController () <UITextViewDelegate, OTRAttachmentPickerDelegate, OTRYapViewHandlerDelegateProtocol, OTRMessagesCollectionViewFlowLayoutSizeProtocol, OTRRoomOccupantsViewControllerDelegate> {
|
|
| 73 | 73 |
JSQMessagesAvatarImage *_warningAvatarImage; |
| 74 | 74 |
JSQMessagesAvatarImage *_accountAvatarImage; |
| 75 | 75 |
JSQMessagesAvatarImage *_buddyAvatarImage; |
| ... | ... | |
| 102 | 102 |
@property (nonatomic, strong) id currentMessage; |
| 103 | 103 |
@property (nonatomic, strong) NSCache *messageSizeCache; |
| 104 | 104 |
|
| 105 |
@property (nonatomic) BOOL automaticURLFetchingDisabled; |
|
| 106 |
@property (nonatomic, strong) OTRMessagesUnknownSenderCell *prototypeCellUnknownSender; |
|
| 107 |
|
|
| 108 | 105 |
@end |
| 109 | 106 |
|
| 110 | 107 |
@implementation OTRMessagesViewController |
| ... | ... | |
| 178 | 175 |
///Custom Layout to account for no bubble cells |
| 179 | 176 |
OTRMessagesCollectionViewFlowLayout *layout = [[OTRMessagesCollectionViewFlowLayout alloc] init]; |
| 180 | 177 |
layout.sizeDelegate = self; |
| 181 |
layout.supplementaryViewDelegate = self; |
|
| 182 | 178 |
self.collectionView.collectionViewLayout = layout; |
| 183 |
UINib *nib = [UINib nibWithNibName:@"OTRMessageUnknownSenderCell" bundle:OTRAssets.resourcesBundle]; |
|
| 184 |
[self.collectionView registerNib:nib forSupplementaryViewOfKind:[OTRMessagesUnknownSenderCell reuseIdentifier] withReuseIdentifier:[OTRMessagesUnknownSenderCell reuseIdentifier]]; |
|
| 185 |
|
|
| 179 |
|
|
| 186 | 180 |
///"Loading Earlier" header view |
| 187 | 181 |
[self.collectionView registerNib:[UINib nibWithNibName:@"OTRMessagesLoadingView" bundle:OTRAssets.resourcesBundle] |
| 188 | 182 |
forSupplementaryViewOfKind:UICollectionElementKindSectionHeader |
| ... | ... | |
| 387 | 381 |
self.threadCollection = collection; |
| 388 | 382 |
[self.readOnlyDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction * _Nonnull transaction) {
|
| 389 | 383 |
self.senderId = [[self threadObjectWithTransaction:transaction] threadAccountIdentifier]; |
| 390 |
self.automaticURLFetchingDisabled = [[self accountWithTransaction:transaction] disableAutomaticURLFetching]; |
|
| 391 | 384 |
}]; |
| 392 | 385 |
|
| 393 | 386 |
// Clear out old state (don't just alloc a new object, we have KVOs attached to this!) |
| ... | ... | |
| 2294 | 2287 |
[self.navigationController.navigationController popViewControllerAnimated:YES]; |
| 2295 | 2288 |
} |
| 2296 | 2289 |
} |
| 2297 |
|
|
| 2298 |
#pragma - mark OTRMessagesCollectionViewFlowLayoutSupplementaryViewProtocol |
|
| 2299 |
|
|
| 2300 |
- (nullable NSArray *)supplementaryViewsForCellAtIndexPath:(NSIndexPath *)indexPath {
|
|
| 2301 |
id<OTRMessageProtocol,JSQMessageData> message = [self messageAtIndexPath:indexPath]; |
|
| 2302 |
if ([self isGroupChat] && [message isKindOfClass:[OTRGroupDownloadMessage class]]) {
|
|
| 2303 |
OTRGroupDownloadMessage *roomMessage = (OTRGroupDownloadMessage *)message; |
|
| 2304 |
// A message that is not automatically downloaded, even though auto download not disabled, means that this is group download message from someone who is not our friend. |
|
| 2305 |
if ([roomMessage.messageError isAutomaticDownloadError] && !self.automaticURLFetchingDisabled && [roomMessage.media isKindOfClass:[OTRImageItem class]]) {
|
|
| 2306 |
if (!_prototypeCellUnknownSender) {
|
|
| 2307 |
UINib *nib = [UINib nibWithNibName:@"OTRMessageUnknownSenderCell" bundle:OTRAssets.resourcesBundle]; |
|
| 2308 |
_prototypeCellUnknownSender = (OTRMessagesUnknownSenderCell *)[nib instantiateWithOwner:self options:nil][0]; |
|
| 2309 |
} |
|
| 2310 |
[self populateUnknownSenderCell:_prototypeCellUnknownSender withMessage:message]; |
|
| 2311 |
[_prototypeCellUnknownSender setNeedsLayout]; |
|
| 2312 |
[_prototypeCellUnknownSender layoutIfNeeded]; |
|
| 2313 |
_prototypeCellUnknownSender.frame = CGRectMake(0, 0, self.collectionView.bounds.size.width, _prototypeCellUnknownSender.frame.size.height); |
|
| 2314 |
int height = [_prototypeCellUnknownSender systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height + 1; |
|
| 2315 |
|
|
| 2316 |
OTRMessagesCollectionSupplementaryViewInfo *info = [[OTRMessagesCollectionSupplementaryViewInfo alloc] initWithKind:[OTRMessagesUnknownSenderCell reuseIdentifier] height:height]; |
|
| 2317 |
return [NSArray arrayWithObject:info]; |
|
| 2318 |
} |
|
| 2319 |
} |
|
| 2320 |
return nil; |
|
| 2321 |
} |
|
| 2322 |
|
|
| 2323 |
- (void)populateUnknownSenderCell:(OTRMessagesUnknownSenderCell *)cell withMessage:(id<OTRMessageProtocol,JSQMessageData>)message {
|
|
| 2324 |
cell.titleLabel.text = [NSString stringWithFormat:ADD_FRIEND_TO_AUTO_DOWNLOAD(), message.senderDisplayName]; |
|
| 2325 |
} |
|
| 2326 |
|
|
| 2327 |
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
|
|
| 2328 |
if ([OTRMessagesUnknownSenderCell.reuseIdentifier isEqualToString:kind]) {
|
|
| 2329 |
id<OTRMessageProtocol,JSQMessageData> message = [self messageAtIndexPath:indexPath]; |
|
| 2330 |
OTRMessagesUnknownSenderCell *cell = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:kind forIndexPath:indexPath]; |
|
| 2331 |
[self populateUnknownSenderCell:cell withMessage:message]; |
|
| 2332 |
return cell; |
|
| 2333 |
} |
|
| 2334 |
// We should never get there, but if we do, don't return nil |
|
| 2335 |
return [[UICollectionReusableView alloc] initWithFrame:CGRectZero]; |
|
| 2336 |
} |
|
| 2337 |
|
|
| 2338 | 2290 |
@end |
Also available in: Unified diff